-
-
Notifications
You must be signed in to change notification settings - Fork 625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
controller open to manage the state. #442
controller open to manage the state. #442
Conversation
@letsar please merge the PR and roll out the new version, this will help me use your plugin from https://pub.dev instead of the git forked version. |
Hi, thank you for the PR and sorry for the delay. I'll do this today. |
We can already get the SlidableAction(
flex: 2,
onPressed: (context) {
Slidable.of(context)?.openEndActionPane();
},
backgroundColor: Color(0xFF7BC043),
foregroundColor: Colors.white,
icon: Icons.archive,
label: 'Archive',
), Is there other use-cases where it would be useful to pass a controller to the |
You are right, but this adds complexity to managing this controller from the parent widgets. final _slidableKey = GlobalKey(); // some code...
return GestureDetector(
onSecondaryTap: widget.swipeable && !widget.selectable
? () => _slidableController.openEndActionPane()
: null,
onLongPress: () => _slidableController.openEndActionPane(),
child: Slidable(
key: _slidableKey,
enabled: widget.swipeable && !widget.selectable,
endActionPane: ActionPane(
extentRatio: extentRatio,
motion: const DrawerMotion(),
children: [
if (widget.conversation.contactType.isUnknown)
ChatListSlidableAction(
label: FlutterI18n.translate(context, 'cta.delete'),
backgroundColor: theme.colorScheme.error,
onPressed: widget.onDeletePressed,
icon: QliqIcons.delete,
)
else ...[
ChatListSlidableAction(
onPressed: widget.onMutePressed,
backgroundColor: AppColors.darkGrey,
icon: widget.conversation.isMuted
? QliqIcons.muteConversation
: QliqIcons.muteConversation,
label: widget.conversation.isMuted
? FlutterI18n.translate(context, 'cta.unmute')
: FlutterI18n.translate(context, 'cta.mute'),
),
ChatListSlidableAction(
onPressed: widget.onStarPressed,
backgroundColor: theme.primaryColor,
icon: widget.conversation.isStarred
? Icons.star
: Icons.star_border,
label: widget.conversation.isStarred
? FlutterI18n.translate(context, 'cta.unstar')
: FlutterI18n.translate(context, 'cta.star'),
),
],
ChatListSlidableAction(
onPressed: widget.onArchivePressed,
backgroundColor: AppColors.darkGrey,
icon: QliqIcons.archiveConversation,
label: FlutterI18n.translate(context, 'cta.archive'),
),
],
),
child: conversationWidget,
),
); /// Since the [Slidable] widget state is private, we need access
/// to its controller for the ability to open the action pane.
///
/// Returns [SlidableController] from [Slidable] widget state.
SlidableController get _slidableController =>
(_slidableKey.currentState as dynamic).controller; // SO HERE is the not-so-good way to get controller, but... So it will be very helpful if the SlidableState is not private then the global key can be typed properly to access the members such as |
Ok I'll merge this then ;-) |
Published in 3.1.0 |
This PR adds the ability to use the controller for the programmatically state management.